<?php

namespace Bean\Db;

class Link extends \Bean\Link {

	private $_data;
	private $_user;
	private static $_links = array();
	
	public function __construct( $data ) {
		parent::__construct();
		$this->_data = $data;
	}
	
	public static function get( $linkId )  {
		if( !isset(self::$_links[$linkId]) ) {
			$data = _q()->get1( 'data_links', array( 'link_id' => $linkId ) );
			self::$_links[$linkId] = new self( $data );
		}
		return self::$_links[$linkId];
	}
	
	public function getImage() {
		return $this->_data['image'];
	}

	public function getTitle() {
		return $this->_data['title'];
	}
	
	public function getDescription() {
		return $this->_data['description'];
	}
	
	public function getUrl() {
		return $this->_data['url'];
	}
	
	public function getSiteName() {
		return $this->_data['site_name'];
	}
	
	public function getLinkId() {
		return $this->_data['link_id'];
	}
	
	public function getUserId() {
		return $this->_data['user_id'];
	}
	
	public function getUser() {
		if( $this->_user === null ) {
			$this->_user = \Bean\User::get( $this->getUserId() );
		}
		return $this->_user;
	}
	
	public function delete() {
		_q()->del( 'data_links', array( 'link_id' => $this->getLinkId() ) );
		return $this;
	}
}
